/*
 * REFXMLSchemaEntity.h
 *
 *  Created on: Mar 31, 2013
 *      Author: Lucifer
 */

#ifndef	__BFX_REFXMLSCHEMAENTITY_H__
#define	__BFX_REFXMLSCHEMAENTITY_H__

#include "../../pch.h"
#include "../core/REFXMLQualifiedName.h"

namespace BFX
{
class REFXMLSchemaEntity : public REFObject
{
public:
	REFXMLSchemaEntity(REFXMLQualifiedName* pName, bool bIsParameter);

	static bool IsPredefinedEntity(const UniString n);

	REFXMLQualifiedName* GetName() const;
	UniString GetUrl() const;
	void SetUrl(const UniString& strUrl);
	UniString GetPubid() const;
	void SetPubid(const UniString& strPubid);
	UniString GetText() const;
	void SetText(const UniString& strText);
	REFXMLQualifiedName* GetNData() const;
	void SetNData(REFXMLQualifiedName* pNdata);

	int GetLineNumber() const;
	void SetLineNumber(int nLineNumber);
	int GetLinePosition() const;
	void SetLinePosition(int nLinePosition);

	bool IsProcessed() const;
	void SetProcessed(bool bIsProcessed);
	bool IsExternal() const;
	void SetExternal(bool bIsExternal);
	bool IsDeclaredInExternal() const;
	void SetDeclaredInExternal(bool bIsDeclaredInExternal);
	bool IsParEntity() const;
	void SetParEntity(bool bIsParEntity);

	UniString GetBaseURI() const;
	void SetBaseURI(const UniString& strBaseURI);
	UniString GetDeclaredURI() const;
	void SetDeclaredURI(const UniString& strDeclaredURI);

private:
	REF<REFXMLQualifiedName>	m_pName;	// Name of entity
	UniString	m_strUrl;					// Url for external entity (system id)
	UniString	m_strPubid;					// Pubid for external entity
	UniString	m_strText;					// Text for internal entity
	REF<REFXMLQualifiedName>	m_pNdata;	// NDATA identifier
	int			m_nLineNumber;				// line number
	int			m_nLinePosition;			// character postion
	bool		m_bIsParameter;				// parameter entity flag
	bool		m_bIsExternal;				// external entity flag
	bool		m_bIsProcessed;				// whether entity is being Processed. (infinite recurrsion check)
	bool		m_bIsDeclaredInExternal;	// declared in external markup or not
	UniString	m_strBaseURI;
	UniString	m_strDeclaredURI;
};

inline REFXMLSchemaEntity::REFXMLSchemaEntity(REFXMLQualifiedName* pName, bool bIsParameter)
{
	m_pName			= pName;
	m_bIsParameter	= bIsParameter;
	m_pNdata		= new REFXMLQualifiedName(UniString(), UniString());	// REFXMLQualifiedName::Empty

	m_nLineNumber = -1;
	m_nLinePosition = -1;
	m_bIsParameter = false;
	m_bIsExternal = false;
	m_bIsDeclaredInExternal = false;
	m_bIsProcessed = false;
}

inline bool REFXMLSchemaEntity::IsPredefinedEntity(const UniString n)
{
	return(n == USTR("lt") ||
		n == USTR("gt") ||
		n == USTR("amp") ||
		n == USTR("apos") ||
		n == USTR("quot"));
}

inline REFXMLQualifiedName* REFXMLSchemaEntity::GetName() const
{
	return m_pName;
}
inline UniString REFXMLSchemaEntity::GetUrl() const
{
	return m_strUrl;
}
inline void REFXMLSchemaEntity::SetUrl(const UniString& strUrl)
{
	m_strUrl = strUrl;
	m_bIsExternal = true;
}
inline UniString REFXMLSchemaEntity::GetPubid() const
{
	return m_strPubid;
}
inline void REFXMLSchemaEntity::SetPubid(const UniString& strPubid)
{
	m_strPubid = strPubid;
}
inline UniString REFXMLSchemaEntity::GetText() const
{
	return m_strText;
}
inline void REFXMLSchemaEntity::SetText(const UniString& strText)
{
	m_strText = strText;
	m_bIsExternal = false;
}
inline REFXMLQualifiedName* REFXMLSchemaEntity::GetNData() const
{
	return m_pNdata;
}
inline void REFXMLSchemaEntity::SetNData(REFXMLQualifiedName* pNdata)
{
	m_pNdata = pNdata;
}
inline int REFXMLSchemaEntity::GetLineNumber() const
{
	return m_nLineNumber;
}
inline void REFXMLSchemaEntity::SetLineNumber(int nLineNumber)
{
	m_nLineNumber = nLineNumber;
}
inline int REFXMLSchemaEntity::GetLinePosition() const
{
	return m_nLinePosition;
}
inline void REFXMLSchemaEntity::SetLinePosition(int nLinePosition)
{
	m_nLinePosition = nLinePosition;
}
inline bool REFXMLSchemaEntity::IsProcessed() const
{
	return m_bIsProcessed;
}
inline void REFXMLSchemaEntity::SetProcessed(bool bIsProcessed)
{
	m_bIsProcessed = bIsProcessed;
}
inline bool REFXMLSchemaEntity::IsExternal() const
{
	return m_bIsExternal;
}
inline void REFXMLSchemaEntity::SetExternal(bool bIsExternal)
{
	m_bIsExternal = bIsExternal;
}
inline bool REFXMLSchemaEntity::IsDeclaredInExternal() const
{
	return m_bIsDeclaredInExternal;
}
inline void REFXMLSchemaEntity::SetDeclaredInExternal(bool bIsDeclaredInExternal)
{
	m_bIsDeclaredInExternal = bIsDeclaredInExternal;
}
inline bool REFXMLSchemaEntity::IsParEntity() const
{
	return m_bIsParameter;
}
inline void REFXMLSchemaEntity::SetParEntity(bool bIsParEntity)
{
	m_bIsParameter = bIsParEntity;
}

inline UniString REFXMLSchemaEntity::GetBaseURI() const
{
	return m_strBaseURI;
}
inline void REFXMLSchemaEntity::SetBaseURI(const UniString& strBaseURI)
{
	m_strBaseURI = strBaseURI;
}
inline UniString REFXMLSchemaEntity::GetDeclaredURI() const
{
	return m_strDeclaredURI;
}
inline void REFXMLSchemaEntity::SetDeclaredURI(const UniString& strDeclaredURI)
{
	m_strDeclaredURI = strDeclaredURI;
}

typedef	REFWrapper<HashMap<REF<REFXMLQualifiedName>, REF<REFXMLSchemaEntity> > >	REFXMLSchemaEntityMap;

}	// namespace BFX

#endif	//	__BFX_REFXMLSCHEMAENTITY_H__
